#!/usr/bin/python
# -*- coding: UTF-8 -*-

from kpautos.engine.case import Case
from kptest.config.enum import DeviceType, HostType, DeviceUtility
from extension.utils import password_generator


class BMC_Redfish_11(Case):
    """
        Name:
            BMC_Redfish_11
        Label:
            创建/查看/删除会话测试
        PreCondition:
            1、BMC正常运行
        TestStep:
            1、发送redfish请求，创建会话，有预期结果A
            2、获取会话SessionID，查看会话，有预期姐结果B
            3、删除会话，有预期结果C
        ExpectedResult:
            A）Redfish可以创建会话
            B）正常显示会话服务信息
            C）会话可以删除
        Parameters:

        Remark:

    """

    # 测试执行前配置等准备操作
    def pre_test_case(self):
        self.device_dut = self.resource.get_device(device_type=DeviceType.Server, utility=DeviceUtility.DUT)
        self.os_host = self.device_dut.get_host(host_type=HostType.HostOS)
        self.redfish_api = self.device_dut.get_api(ns_name="Redfish")

        # 测试步骤
    def procedure(self):
        self.log_step(" 1、发送redfish请求，创建会话")
        result = self.redfish_api.redfish_session_create_session("Administrator", "Admin@12#$")
        self.logger.info(f"Redfish查询到的创建会话的返回信息为：{result}")
        if result == None:
            raise Exception("Redfish创建会话失败")
        self.log_step(" 2、获取会话ID，查看会话")
        sessionId = result["Id"]
        self.log_debug(f"sessionID为: {sessionId}")
        result = self.redfish_api.redfish_session_query_session_id(sessionId)
        if result == None:
            raise Exception("查看会话失败")
        self.logger.info(f"Redfish查看指定SessionID会话返回信息为：{result}")
        self.log_step(" 3、删除会话")
        result = self.redfish_api.redfish_session_delete_session(sessionId)
        if result == None:
            raise Exception("删除会话失败")
        self.logger.info(f"Redfish删除指定SessionID会话返回信息为：{result}")




    # 测试结束后恢复环境
    def post_test_case(self):
        pass
